<?
	session_start();
	require_once("../php/global.php");
	require(ROOT."php/classes.php");
	require_once(ROOT."root/author.php");
	require_once(ROOT."root/updavee.php");
	$pager="物流方式";
	$dave=$emss;
	$dave->rows=15;
	$page='ems';
	// settings info
	$a = @$_GET["a"];
	$uid=0;
	if (isset($_GET["uid"])) $uid = @$_GET["uid"];
	$sql = @$_POST["sql"];
	if($id==0){
		$page_num=1;
		$kind=0;
		$order='csort';
		if (isset($_GET["page"]))if(is_numeric($_GET["page"]))$page_num=$_GET["page"];
		$total_rows=$dave->count_total_rows();
		$total_pages=$dave->count_total_pages();
		$info=$dave->show_page($page_num-1,$order);
	}
	else $info=$dave->echo_only($uid);
?>
<!DOCTYPE HTML><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	
<title>Admin</title>
<? require_once("lib.php"); ?>
</head>
<body>
<div class="content-box"><!-- Start Content Box -->
    <div class="content-box-header">
        <h3><? echo $pager ?></h3>
        <div class="clear"></div>
    </div> <!-- End .content-box-header -->
    <div class="content-box-content">
<?
  switch ($sql) {
    case "update":
    	sql_update();
    	break;
	case "add":
		sql_insert();
		break;
  }
  switch ($a) {
    case "add":
    	add();
    	break;
	case "update":
		update($uid);
		break;
	case "delete":
		delete($uid);
		break;
    default:	
		show_info();
  }
 ?>
        <? function show_box($row, $iseditmode, $isadd){ 
			global $uid, $sorts, $siteurl, $h;
		?>
        	<table width="99%" cellspacing="0" cellpadding="3" class="mbox">
              <tr class="th"><td class="thtitle" width="25%" align="right"><? echo $pager ?></td><td><? $h->hidden('id', $row["id"]); ?></td></tr>
              <tr><td class="l">名字</td><td><? $h->text('cname', $row["cname"], 'g') ?></td></tr>
              <tr><td class="l">序号</td><td><? $h->text('csort', $row["csort"], 'g') ?> <span class="red"> * 序号越大越优先显示</span></td></tr>
              <tr><td class="l">&nbsp;</td><td><br><? $h->submit('save', '&nbsp; 提交保存 &nbsp;', $iseditmode==1?'':'hide') ?>&nbsp; <a onClick="history.go(-1)">[ 返回 ]</a><br><br></td></tr>
            </table>
            <? } ?>
			<? function show_boxes($result){ 
				global $page_num, $total_pages, $kind, $sorts, $siteurl, $page;
        		echo '<table width="99%" cellspacing="0" cellpadding="3" class="mlist" id="picbox"><tr class="th"><td><strong>#</strong></td><td><strong>名字</strong></td><td><strong>序号</strong></td><td><a href="'.$page.'.php?a=add">[ 添加 ]</a></td></tr>';
				$count=1;
            	while($row=mysql_fetch_array($result))
				{
					$uid=decode($row['id']);
              		$str="<tr><td>".$row['id'].".</td><td><a href=\"$page.php?a=update&uid=".decode($row['id'])."\">".decode($row['cname'])."</a></td><td>".decode($row['csort'])."</td><td>";
					$str.="<a href=\"$page.php?a=delete&uid=".decode($row['id'])."\" onClick=\"return delc();\">删除</a></td></tr>";              
					echo $str;
					$count++;
				}
				echo "</table>";
				if($count==1) echo "<br>No data now. (暂无数据!)";
				echo echo_page($page_num, $total_pages, $page.'-'.$kind.'-p');
             } ?>
         <br class="clear" />
				</div> <!-- End .content-box-content -->
                     <br class="clear" />
			</div><!-- End .content-box -->
</body>
</html>
<?
	function add()
	{
		global $page,$h;
		$row = array();
		$h->form($page.'.php', 0, '');
		show_box($row, true, ture);		
		$h->hidden('sql', 'add');
		$h->former();
	}
	function update($uid)
	{
		global $dave, $page,$h;
		if($uid=="") 
		{
			echo "Invali argument!!!";
			exit;
		}
		$info=$dave->echo_only($uid);
		$h->form($page.'.php', 0, '');
	  	show_box($info, true, false);
		$h->hidden('sql', 'update');
		$h->former();
	}
	function delete($uid)
	{
		global $dave,$page;
		if($dave->delete($uid))
		echo "<script>location='$page.php';</script>";
	}	
	function show_info()
	{
		global $dave;
		global $info;
		global $uid;
		if($uid==0)
		{
	  	show_boxes($info);
		}
		else 
		{
			show_box($info, false);
		}
	}
	function sql_insert()
	{
		global $dave,$page;
		$arr=array(
			'cname'=>iso(@$_POST["cname"]),
			'csort'=>iso(@$_POST["csort"]),
		);
		if($dave->insert($arr))
		echo '<script type="text/javascript">location="'.$page.'.php";</script>';
	}
	function sql_update()
	{
		global $dave,$page;
		$id=iso(@$_POST["id"]);
		$arr=array(
			'cname'=>iso(@$_POST["cname"]),
			'csort'=>iso(@$_POST["csort"]),
		);
		if($dave->update($arr,'id',$id))
		echo '<script type="text/javascript">location="'.$page.'.php";</script>';
	}
?>